package com.tmxk.employee.utils.redis;

import redis.clients.jedis.Jedis;

/**
 * redis缓存数据库连接
 */
public class RedisConn {
    //url  port  pwd
    protected static String url = "192.168.0.100";
    protected static int port = 6379;
    protected static String pwd = "123456";

    //连接redis
    public Jedis connRedis(){
        Jedis jedis = new Jedis(url,port);
        jedis.auth(pwd);
        return jedis;
    }

    /**
     * 存储string类型的数据
     * @param key 键
     * @param val 值
     * @param cycleTime  时间周期
     * @return
     */
    public boolean saveData(String key,String val,long cycleTime){
        Jedis jedis = connRedis();
        //存储值
        jedis.set(key,val);
        //设置失效周期
        jedis.expire(key,cycleTime);
        //获取key是否存在
        return jedis.exists(key);
    }
}
